import flowLineItemComp from './flowLineItem.vue'
import flowLineItemDetail from './flowLineItemDetail.vue'
import Vue from "vue";

var flowLineItem = {
    type:'flowLineItem',//item类型
    checked:false,
    icon:'el-icon-sunset',//item图标
    txt:'流动条', //item名称    
    methods:{
        install:function(item,page,event){//选中图标页面点击事件,命名规则`${item.type}Install`            
            return Object.assign({
                type:'flowLineItem',
                width:0,                
                height:10,
                state:0,
                x1:item['x1']?item.x1:item.pageSize.width-item.x<100?item.x-50:item.x+50,
                y1:item['y1']?item.y1:item.y,
                color:'rgb(86, 136, 222)',
                borderColor:'#000000'
            }, item);            
        },
        render:function(refs,item){        
            var comp=Vue.extend(flowLineItemComp);
            var instance=new comp({
                propsData:{
                    attr:item
                }
            });
            instance.$mount();
            refs.appendChild(instance.$el);
        },
        detailRender:function(refs,item){//加载详细信息控件,命名规则`${item.type}DetailRender`       
            var comp=Vue.extend(flowLineItemDetail);
            var instance=new comp({
                propsData:{
                    attr:item
                }
            });
            instance.$mount();
            //console.log('flowLineItemRenderDetial to refs',refs,instance);
            refs.appendChild(instance.$el);
        },
        dragableX:function(item,moveXY,event){
            if(item.lock) return true;
            return moveXY.x+item.x>=0 
                && moveXY.x+item.x<=item.pageSize.width-item.width
                && moveXY.x+item.x1>=0 
                && moveXY.x+item.x1<=item.pageSize.width-item.width;
        },
        dragableY:function(item,moveXY,event){
            if(item.lock) return true;
            return moveXY.y+item.y-item.height/2>=0 
                && moveXY.y+item.y<=item.pageSize.height-item.height
                && moveXY.y+item.y1-item.height/2>=0 
                && moveXY.y+item.y1<=item.pageSize.height-item.height;
        },
        dragX:function(item,moveXY,event){
            if(item.lock) return;
            item.x=moveXY.x+item.x;
            item.x1=moveXY.x+item.x1;
        },
        dragY:function(item,moveXY,event){
            if(item.lock) return;
            item.y=moveXY.y+item.y;
            item.y1=moveXY.y+item.y1;
        },
        pasteXY:function(item){
            item.x=item.x+30;
            item.y=item.y+30;
            item.x1=item.x1+30;
            item.y1=item.y1+30;
        }
    }
}

export default flowLineItem;